﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <title></title>
    <link href="main.css" rel="stylesheet" type="text/css" />
 
    <link href="test.css" rel="stylesheet" type="text/css" />

    <style>
        .reading h2 {
            width: 100%;
            margin: 20px 0 70px;
            text-align: center;
            line-height: 2;
            font-size: 20px;
            color: #59595b;
        }

        .reading h2 a {
            text-decoration: none;
            color: #59595b;
            font-size: 20px;
        }

        .reading h2 a:hover {
            color: #2183f1;
        }
    </style>
</head>
<script src="jquery-1.11.3.min.js"></script>
<script src="jquery.countdown.js"></script>
<script>
    $(function () {
        var requestid =  getUrlParam("requestid");
        var jsonArr = '';
        $.ajax({
            type: "post",
            async: false,
            //url: '/api/weaXfjtWebApi/getApprovalTest',
            url: '/interface/xfjt/getApprovalTest.jsp',
            dataType: 'json',
            data: {'requestid':requestid},
            success: function (data) {
                jsonArr = data;
            }
        });

        $('.test_name').text(jsonArr.examname);
        $('.test_datetime').text("时间:"+jsonArr.exambegdate+"至"+jsonArr.examenddate);
        $('.alt-1').text(jsonArr.examtime);
        $("#dxt_title").children().children().eq(1).text(jsonArr.dxttitle);
        $("#duoxt_title").children().children().eq(1).text(jsonArr.duoxttitle);
        $("#pdt_title").children().children().eq(1).text(jsonArr.pdttitle);
        $("#jdt_title").children().children().eq(1).text(jsonArr.jdttitle);
        var dxt_exam = '';
        if(jsonArr.dxt.length>0) {
            jsonArr.dxt.map(function(item, index){
                var options = '';
                item.child.map(function(lt, dx) {
                    var option =
                        "<li class='option'>" +
                        "<input type='radio' class='radioOrCheck' name='0_answer" + (index + 1) + "' id='0_answer_" + (index + 1) + "_option_" + (dx + 1) + "' value='" + lt.xxid + "'/>" +
                        "<label for='0_answer_" + (index + 1) + "_option_" + (dx + 1) + "'>" + lt.xxmc +
                        "<p class='ue' style='display: inline;'>" + lt.xxnr + "</p>" +
                        "</label>" +
                        "</li>";
                    options += option;
                })

                var exam_li_test_i = "<i>" + (index + 1) + "</i><span></span><font>" + item.tm + " (" + item.fz + ")分</font></b>";
                var exam_li_test = "<div class='test_content_nr_tt'>" + exam_li_test_i + "</div>";
                var exam_li_option_ul = "<ul>" + options + "</ul>";
                var exam_li_option = "<div class='test_content_nr_main'>" + exam_li_option_ul + "</div>";
                var exam_li = "<li id='qu_0_" + index + "'>" + exam_li_test + exam_li_option + " </li>";
                dxt_exam += exam_li;
            });
        }else {
            $("#dxt_title").hide();
        }
        $("#dxt_content").children().append(dxt_exam);
        jsonArr.dxt.map(function(item){
            if(item.da.xzdaid !='') {
                $("#qu_" + item.xh).find("input[type='radio']").eq((item.da.xzdaid - 1)).attr("checked", true);
            }
        });

        var duozt_exam = '';
        if(jsonArr.duoxt.length>0){
            jsonArr.duoxt.map(function(item,index){
            var options = '';
            item.child.map(function(lt,dx){
                var option =
                    "<li class='option'>" +
                    "<input type='checkbox' class='radioOrCheck' name='1_answer"+(index+1)+"' id='1_answer_"+(index+1)+"_option_"+(dx+1)+"' value='"+lt.xxid+"'/>" +
                    "<label for='1_answer_"+(index+1)+"_option_"+(dx+1)+"'>" +lt.xxmc+
                    "<p class='ue' style='display: inline;'>"+lt.xxnr+"</p>" +
                    "</label>" +
                    "</li>";
                options +=option;
            })

            var exam_li_test_i = "<i>"+(index+1)+"</i><span></span><font>"+item.tm+" ("+item.fz+")分</font>";
            var exam_li_test = "<div class='test_content_nr_tt'>"+exam_li_test_i+"</div>";
            var exam_li_option_ul =  "<ul>"+options+"</ul>";
            var exam_li_option =  "<div class='test_content_nr_main'>"+exam_li_option_ul+"</div>";
            var exam_li = "<li id='qu_1_"+index+"'>"+exam_li_test+exam_li_option+" </li>";
            duozt_exam +=exam_li;
        });
        }else {
            $("#duoxt_title").hide();
        }
        $("#duoxt_content").children().append(duozt_exam);
        jsonArr.duoxt.map(function(item){
            if(item.da.xzdaid !='') {
                var arr = item.da.xzdaid.split(",");
                for (var i = 0; i < arr.length; i++) {
                    $("#qu_" + item.xh).find("input[type='checkbox']").eq(arr[i] - 1).attr("checked", true);
                }
            }
        });

        var pdt_exam = '';
        if(jsonArr.pdt.length>0){
            jsonArr.pdt.map(function(item,index){
            var options = '';
            item.child.map(function(lt,dx){
                var option =
                    "<li class='option'>" +
                    "<input type='radio' class='radioOrCheck' name='2_answer"+(index+1)+"' id='2_answer_"+(index+1)+"_option_"+(dx+1)+"' value='"+lt.xxid+"'/>" +
                    "<label for='2_answer_"+(index+1)+"_option_"+(dx+1)+"'>" +lt.xxmc+
                    "</label>" +
                    "</li>";
                options +=option;
            })

            var exam_li_test_i = "<i>"+(index+1)+"</i><span></span><font>"+item.tm+" ("+item.fz+")分</font>";
            var exam_li_test = "<div class='test_content_nr_tt'>"+exam_li_test_i+"</div>";
            var exam_li_option_ul =  "<ul>"+options+"</ul>";
            var exam_li_option =  "<div class='test_content_nr_main'>"+exam_li_option_ul+"</div>";
            var exam_li = "<li id='qu_2_"+index+"'>"+exam_li_test+exam_li_option+" </li>";
            pdt_exam +=exam_li;
        });
        }else {
            $("#pdt_title").hide();
        }
        $("#pdt_content").children().append(pdt_exam);
        jsonArr.pdt.map(function(item){
            if(item.da.xzdaid !='') {
                $("#qu_" + item.xh).find("input[type='radio']").eq((item.da.xzdaid - 1)).attr("checked", true);
            }
        });

        var jdt_exam = '';
        if(jsonArr.jdt.length>0){
            jsonArr.jdt.map(function(item,index){
            var options = '';
            item.child.map(function(lt,dx){
                var option =
                    "<li>" +
                    "<textarea class='textarea' name='3_answer"+(index+1)+"' id='3_answer_"+(index+1)+"_option_"+(dx+1)+"'></textarea>" +
                    "</li>";
                options +=option;
            })

            var exam_li_test_i = "<i>"+(index+1)+"</i><span></span><font>"+item.tm+ "("+item.fz+")分"+
                "<span class='inputspan'>打分输入框:<input type='number' class='inputnumber'  oninput='if(value>"+item.fz+")value="+item.fz+";if(value<0)value=0'/>分</span></font>";
            var exam_li_test = "<div class='test_content_nr_tt'>"+exam_li_test_i+"</div>";
            var exam_li_option_ul =  "<ul>"+options+"</ul>";
            var exam_li_option =  "<div class='test_content_nr_main'>"+exam_li_option_ul+"</div>";
            var exam_li = "<li id='qu_3_"+index+"'>"+exam_li_test+exam_li_option+" </li>";
            jdt_exam +=exam_li;
        });
        }else {
            $("#jdt_title").hide();
        }
        $("#jdt_content").children().append(jdt_exam);
        jsonArr.jdt.map(function(item){
            $("#qu_"+item.xh).find('textarea').eq(0).val(item.da.xzdamc);
        });

        $("#submitbtn").click(function() {
            var jdtarr = [];
            jsonArr.jdt.map(function(item){
                var score_val = $("#qu_"+item.xh).find('.inputnumber').val();
                jdtarr.push({'xh':item.xh,'score':score_val})
            });
            var params = {'jdt':jdtarr};
            $.ajax({
                type: "post",
                async: false,
                url: "/interface/xfjt/submitScore_Ajax.jsp",
                dataType: 'json',
                data: { 'requestid':requestid,'result':JSON.stringify(params)},
                success: function (data) {
                    getKsdf(requestid);
                    if(data.status){
                        localStorage.setItem('reloadTab','0')
                        window.close();
                    }
                    submitWf(requestid);
                }
            });
        })

        $(':radio').attr('disabled', true);
        $(':checkbox').attr('disabled', true);
        $('.textarea').attr('readonly','readonly');
    });
    //获取url地址参数
    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
        var r = window.location.search.substr(1).match(reg);  //匹配目标参数
        if (r != null) return unescape(r[2]);
        return null; //返回参数值
    }
    function getKsdf(requestid){
        var flag = false;
        $.ajax({
            type: "get",
            async: false,
            url: "/interface/xfjt/getKsdf_Ajax.jsp",
            dataType: 'json',
            data: { requestid: requestid},
            success: function (data) {
                flag = data.flag;
            }
        });
        return flag;
    }
    //获取url地址参数
    function submitWf(requestid) {
        var datas = "";
        $.ajax({
            type: "post",
            async: false,
            url: "/interface/xfjt/submitWf_Ajax.jsp",
            dataType: 'json',
            data: { 'requestid':requestid},
            success: function (data) {
                datas = data;
                getKsdf(requestid);
            }
        });
        return datas;
    }

</script>


<body>
    <div class="main">
        <div class="header"></div>
        <!--nr start-->
        <div class="test_main">
            <div class="nr_left">
                <div class="test">
                    <form>
                        <!--标题-->
                        <div class="test_title">
                            <p class="test_time">
                                <i class="icon iconfont">考试时长:</i><b class="alt-1"></b>
                            </p>
                            <font><input type="button" id="submitbtn" name="test_jiaojuan" value="提交"></font>
                        </div>
                        <div class="test_content">
                            <div class="test_content_title">
                                <b class="test_name"></b>
                                <b class="test_datetime"></b>
                            </div>
                        </div>
                        <!--单选题-->
                        <div id="dxt_title" class="test_content">
                            <div class="test_content_title">
                                <h2>单选题</h2>
                                <p><span></span></p>
                            </div>
                        </div>
                        <div id="dxt_content" class="test_content_nr">
                            <ul></ul>
                        </div>
                        <!--多选题-->
                        <div id="duoxt_title" class="test_content">
                            <div class="test_content_title">
                                <h2>多选题</h2>
                                <p><span></span></p>
                            </div>
                        </div>
                        <div id="duoxt_content" class="test_content_nr">
                            <ul></ul>
                        </div>
                        <!--判断题-->
                        <div id="pdt_title" class="test_content">
                            <div class="test_content_title">
                                <h2>判断题</h2>
                                <p><span></span></p>
                            </div>
                        </div>
                        <div id="pdt_content" class="test_content_nr">
                            <ul></ul>
                        </div>
                        <!--简答题-->
                        <div id="jdt_title" class="test_content">
                            <div class="test_content_title">
                                <h2>简答题</h2>
                                <p><span></span></p>
                            </div>
                        </div>
                        <div id="jdt_content" class="test_content_nr">
                            <ul></ul>
                        </div>
                    </form>
                </div>

            </div>

        </div>
        <!--nr end-->
        <div class="foot"></div>
    </div>
</body>
</html>

